package org.lq.us.commons;

import java.util.List;

public class Page<T> {
	
	private List<T> list = null;//展示当前页数据
	private int currentPageNum; //当前页数
	private int pageSize = 10; //每页显示的条数
	private int totalCount;// 数据的总行数
	private int startIndex;// 开始页数
	private int totalPageCount; //总页数
	private int nextPageNum;//下一页
	private int prePageNum; //上一页
	private String fieldName;//需要排序的列
	private String orderType="asc"; //排序方式
	
	
	public Page(int currentPageNum,int pageSize,int totalCount) {
		this.currentPageNum = currentPageNum;
		this.pageSize = pageSize;
		this.totalCount = totalCount;
		
		getStartIndex();
		
		this.totalPageCount = totalCount % pageSize == 0 ? totalCount/pageSize : totalCount / pageSize +1;
			
	}
	/**
	 * 计算开始位置
	 * @return
	 */
	public int getStartIndex() {
		this.startIndex = (this.currentPageNum-1) * this.pageSize;
		return startIndex;
	}
	public int getNextPageNum() {
		this.nextPageNum = currentPageNum+1;
		return nextPageNum >= totalPageCount ? totalPageCount : nextPageNum;
	}
	public int getPrePageNum() {
		this.prePageNum = currentPageNum - 1;
		return prePageNum<=1 ? 1 : prePageNum;
	}
	//------------------------------------
	
	public List<T> getList() {
		return list;
	}
	public void setList(List<T> list) {
		this.list = list;
	}
	public int getCurrentPageNum() {
		return currentPageNum;
	}
	public void setCurrentPageNum(int currentPageNum) {
		this.currentPageNum = currentPageNum;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	
	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}
	public int getTotalPageCount() {
		return totalPageCount;
	}
	public void setTotalPageCount(int totalPageCount) {
		this.totalPageCount = totalPageCount;
	}

	public void setNextPageNum(int nextPageNum) {
		this.nextPageNum = nextPageNum;
	}
	
	public void setPrePageNum(int prePageNum) {
		this.prePageNum = prePageNum;
	}
	public String getFieldName() {
		return fieldName;
	}
	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}
	public String getOrderType() {
		return orderType;
	}
	public void setOrderType(String orderType) {
		this.orderType = orderType;
	}
	


}
